﻿using JESAI.Redis.Abstracts.Commadns;
using JESAI.Redis.Abstracts.Commands;
using JESAI.Redis.Builders;
using JESAI.Redis.Datas;
using JESAI.Redis.Pools;
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace JESAI.Redis.Abstracts.RedisClients
{
    public interface IRedisClient : IDisposable, IObjectPool
    {

        /// <summary>
        /// 连接信息
        /// </summary>
        public IConnectionBuilder ConnectionBuilder { get; }

        /// <summary>
        /// 键
        /// </summary>
        public string Key { get; }

        /// <summary>
        /// 客户端ID
        /// </summary>
        public string ClientId { get; }

        /// <summary>
        /// 当前连接的主机信息
        /// </summary>
        public string RedisHost { get; }

        public DateTime LastUseTime { get; set; }

        /// <summary>
        /// 当前连接的端口信息
        /// </summary>
        public int Port { get; }

        /// <summary>
        /// 当前db
        /// </summary>
        public int CurrentDBIndex { get; }

        public int TargetDBIndex { get; }

        /// <summary>
        /// 是否关闭
        /// </summary>
        public bool IsClose { get; }

        /// <summary>
        /// 初始化客户端
        /// </summary>
        /// <returns></returns>
        public Task InitClientAsync();

        public Task<T> ExecuteAsync<T>(IRedisCommandArg commandArg);
        public Task<RedisData> ExecuteSampleAsync(IRedisCommandArg commandArg);

        public Task ExecuteNoResultAsync(IRedisCommandArg commandArg);

        Task<object> ReadMessageAsync();

        Task<RedisData> InvokeAsync(IRedisCommandArg commandArg);
        Task<bool> PingAsync();
        Task<bool> ChangeDb(int dbIndex);

        Task<bool> AuthAsync(string userName, string password);

        Task<bool> QuitAsync();

        Task ReconnectAsync(CancellationToken cancellationToken = default);

        Task ReconnectSocketAsync(CancellationToken cancellationToken = default);

        /// <summary>
        /// 关闭
        /// </summary>
        public void Close();
    }
}
